package com.itls.recommendedgames.service.Impl;

import com.itls.recommendedgames.entity.User;
import com.itls.recommendedgames.mapper.UserMapper;
import com.itls.recommendedgames.service.UserService;
import jakarta.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public void insertUser(User user) {
        String rawPassword = user.getPassword();
        String encodedPassword = passwordEncoder.encode(rawPassword);
        user.setPassword(encodedPassword);
          userMapper.insertUser(user);
    }

    @Override
    public User find(User user) {
      System.out.println(user);
        User user1 = userMapper.find(user);
        if (passwordEncoder.matches(user.getPassword(), user1.getPassword())) {
            return user1; // 密码正确，返回用户
        } else {
            return null; // 密码错误
        }
    }

}
